package com.yztc.ui.home;

import com.yztc.bean.home.HomeFragmentBean;
import com.yztc.http.RetrofitService;
import com.yztc.base.OnLoadListener;
import com.yztc.utils.HttpHelper;

import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by My on 2016/10/6.
 */
public class HomeModle implements HomeConstract.IHomeModle {

    @Override
    public void LoadNewsData(String baseUrl, final OnLoadListener listener) {
        Observable observable = (Observable) HttpHelper
                .getInstance()
                .getRetrofit(baseUrl)
                .create(RetrofitService.class)
                .getHomeFragmentBean();
       observable.subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new Observer<HomeFragmentBean>(){

                     @Override
                     public void onCompleted() {

                     }

                     @Override
                     public void onError(Throwable e) {
                         listener.onFailure(e);
                     }

                     @Override
                     public void onNext(HomeFragmentBean homeFragmentBean) {
                        listener.onSuccess(homeFragmentBean);
                     }
                 });
    }
}
